﻿using Super.Admin.Utils.EventAggregator.EventType;
using Super.Admin.Utils.EventAggregator;
using Super.Admin.Utils.ThemeManager;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Super.Admin.Views.Main
{
    public partial class UcMainDrawerSettingGeneralSetting : UserControl
    {
        private bool _isLoad = false;
        public UcMainDrawerSettingGeneralSetting()
        {
            InitializeComponent();
            this.Load += UcMainDrawerSettingGeneralSetting_Load;
        }

        private void UcMainDrawerSettingGeneralSetting_Load(object? sender, EventArgs e)
        {
            _isLoad = true;
            InitializeControls();
            // 初始化本地参数
            InitializeLoadConfig();
            _isLoad = false;
        }

        private void InitializeControls()
        {
            CmbLanguage.Items.AddRange(new object[] { "简体中文", "English", "日本語で" });
        }

        private void InitializeLoadConfig()
        {
            // 语言
            CmbLanguage.SelectedValue = CmbLanguage.Items[(int)ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.Language];
            BtnSwitchAnimationEnablement.Checked = ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.AnimationEnablement;
            BtnSwitchShadowEnablement.Checked = ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.ShadowEnablement;
            BtnSwitchScrollBarHiddenStyle.Checked = ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.ScrollBarHiddenStyle;
            BtnSwitchHighQualityPresentationOfText.Checked = ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.HighQualityPresentationOfText;
            BtnSwitchRegularlyCheckForUpdates.Checked = ThemeSettingHelper.Instance.ThemeConfig.GeneralSettings.General.RegularlyCheckForUpdates;
        }

        private void CmbLanguage_SelectedValueChanged(object sender, AntdUI.ObjectNEventArgs e)
        {
            if (_isLoad) return;
            EventAggregator.Default.Publish<GeneralSettingEvent>(new GeneralSettingEvent { Type = GeneralSettingEvent.GeneralSettingType.SwitchLanguage, Value = CmbLanguage.Items.IndexOf(e.Value) });
        }

        private void BtnSwitch_CheckedChanged(object sender, AntdUI.BoolEventArgs e)
        {
            if (_isLoad) return;
            AntdUI.Switch @switch = (AntdUI.Switch)sender;
            switch (@switch.Name)
            {
                case "BtnSwitchAnimationEnablement":
                    EventAggregator.Default.Publish<GeneralSettingEvent>(new GeneralSettingEvent { Type = GeneralSettingEvent.GeneralSettingType.AnimationEnablement, Value = e.Value});
                    break;
                case "BtnSwitchShadowEnablement":
                    EventAggregator.Default.Publish<GeneralSettingEvent>(new GeneralSettingEvent { Type = GeneralSettingEvent.GeneralSettingType.ShadowEnablement, Value = e.Value});
                    break;
                case "BtnSwitchScrollBarHiddenStyle":
                    EventAggregator.Default.Publish<GeneralSettingEvent>(new GeneralSettingEvent { Type = GeneralSettingEvent.GeneralSettingType.ScrollBarHiddenStyle, Value = e.Value});
                    break;
                case "BtnSwitchHighQualityPresentationOfText":
                    EventAggregator.Default.Publish<GeneralSettingEvent>(new GeneralSettingEvent { Type = GeneralSettingEvent.GeneralSettingType.HighQualityPresentationOfText, Value = e.Value});
                    break;
                case "BtnSwitchRegularlyCheckForUpdates":
                    EventAggregator.Default.Publish<GeneralSettingEvent>(new GeneralSettingEvent { Type = GeneralSettingEvent.GeneralSettingType.RegularlyCheckForUpdates, Value = e.Value});
                    break;
            }
        }
    }
}
